home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 June / PersonalComputerWorld-June2009-CoverdiscCD.iso / Software / Freeware / Firebug 1.3.3 / firebug-1.3.3-fx.xpi / content / firebug / search.js < prev    next >
Encoding:
JavaScript  |  2009-02-19  |  4.1 KB  |  154 lines

  1. /* See license.txt for terms of usage */
  2.  
  3. FBL.ns(function() { with (FBL) {
  4.  
  5. // ************************************************************************************************
  6. // Constants
  7.  
  8. const searchDelay = 150;
  9.  
  10. // ************************************************************************************************
  11.  
  12. Firebug.Search = extend(Firebug.Module,
  13. {
  14.     search: function(text, context)
  15.     {
  16.         var searchBox = context.chrome.$("fbSearchBox");
  17.         searchBox.value = text;
  18.         this.update(context);
  19.     },
  20.  
  21.     enter: function(context)
  22.     {
  23.         var panel = context.chrome.getSelectedPanel();
  24.         if (!panel.searchable)
  25.             return;
  26.  
  27.         var searchBox = context.chrome.$("fbSearchBox");
  28.         var value = searchBox.value;
  29.  
  30.         panel.search(value, true);
  31.     },
  32.  
  33.     cancel: function(context)
  34.     {
  35.         this.search("", context);
  36.     },
  37.  
  38.     clear: function(context)
  39.     {
  40.         var searchBox = context.chrome.$("fbSearchBox");
  41.         searchBox.value = "";
  42.     },
  43.  
  44.     displayOnly: function(text, context)
  45.     {
  46.         var searchBox = context.chrome.$("fbSearchBox");
  47.  
  48.         if (text && text.length > 0)
  49.             setClass(searchBox, "fbSearchBox-attention");
  50.         else
  51.             removeClass(searchBox, "fbSearchBox-attention");
  52.  
  53.         searchBox.value = text;
  54.     },
  55.  
  56.     focus: function(context)
  57.     {
  58.         if (context.detached)
  59.             context.chrome.focus();
  60.         else
  61.             Firebug.toggleBar(true);
  62.  
  63.         var searchBox = context.chrome.$("fbSearchBox");
  64.         searchBox.focus();
  65.         searchBox.select();
  66.     },
  67.  
  68.     update: function(context, immediate)
  69.     {
  70.         var panel = context.chrome.getSelectedPanel();
  71.         if (!panel.searchable)
  72.             return;
  73.  
  74.         var searchBox = context.chrome.$("fbSearchBox");
  75.         var panelNode = panel.panelNode;
  76.  
  77.         var value = searchBox.value;
  78.  
  79.         // This sucks, but the find service won't match nodes that are invisible, so we
  80.         // have to make sure to make them all visible unless the user is appending to the
  81.         // last string, in which case it's ok to just search the set of visible nodes
  82.         if (!panel.searchText || value.indexOf(panel.searchText) != 0)
  83.             removeClass(panelNode, "searching");
  84.  
  85.         // Cancel the previous search to keep typing smooth
  86.         clearTimeout(panelNode.searchTimeout);
  87.  
  88.         if (immediate)
  89.         {
  90.             var found = panel.search(value);
  91.             if (!found && value)
  92.                 beep();
  93.  
  94.             panel.searchText = value;
  95.         }
  96.         else
  97.         {
  98.             // After a delay, perform the search
  99.             panelNode.searchTimeout = setTimeout(function()
  100.             {
  101.                 if (value)
  102.                 {
  103.                     // Hides all nodes that didn't pass the filter
  104.                     setClass(panelNode, "searching");
  105.                 }
  106.                 else
  107.                 {
  108.                     // Makes all nodes visible again
  109.                     removeClass(panelNode, "searching");
  110.                 }
  111.  
  112.                 var found = panel.search(value);
  113.                 if (!found && value)
  114.                     beep();
  115.  
  116.                 panel.searchText = value;
  117.             }, searchDelay);
  118.         }
  119.     },
  120.  
  121.     // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  122.     // extends Module
  123.  
  124.     enable: function()
  125.     {
  126.         var searchBox = FirebugChrome.$("fbSearchBox");
  127.         searchBox.value = "";
  128.         searchBox.disabled = false;
  129.     },
  130.  
  131.     disable: function()
  132.     {
  133.         var searchBox = FirebugChrome.$("fbSearchBox");
  134.         searchBox.value = "";
  135.         searchBox.disabled = true;
  136.     },
  137.  
  138.     showPanel: function(browser, panel)
  139.     {
  140.         var chrome = browser.chrome;
  141.         var searchBox = chrome.$("fbSearchBox");
  142.         searchBox.value = panel && panel.searchText ? panel.searchText : "";
  143.         searchBox.disabled = !panel || !panel.searchable;
  144.     }
  145. });
  146.  
  147. // ************************************************************************************************
  148.  
  149. Firebug.registerModule(Firebug.Search);
  150.  
  151. // ************************************************************************************************
  152.  
  153. }});
  154.